import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'home_pages/adaptive_page.dart';
import 'home_pages/phone_page.dart';

///
/// 那时我们有梦
/// 关于文学
/// 关于爱情
/// 关于穿越世界的旅行
/// 如今我们深夜饮酒
/// 杯子碰到一起
/// 都是梦破碎的声音
///

class FunctionSelectPage extends StatefulWidget {
  const FunctionSelectPage({super.key});

  @override
  State<FunctionSelectPage> createState() => _FunctionSelectPageState();
}

class _FunctionSelectPageState extends State<FunctionSelectPage> {
  final List<ClickItem> items = [
    // ClickItem('详情页面Scaffold', ),
    ClickItem('手机类型Scaffold', 'phone'),
    ClickItem('可变Scaffold', 'adaptive'),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("这是标题"),
      ),
      body: ListView.separated(
        itemBuilder: (ctx, index) => _Item(item: items[index]),
        separatorBuilder: (BuildContext context, int index) => Divider(),
        itemCount: items.length,
      ),
    );
  }
}

class _Item extends StatelessWidget {
  final ClickItem item;

  const _Item({super.key, required this.item});

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(item.title),
      subtitle: Text(item.subTitle),
      trailing: Icon(Icons.chevron_right),
      onTap: () {
        if (item.subTitle == 'phone') {
          Navigator.of(context).push(MaterialPageRoute(
              builder: (ctx) => PhonePage(
                    title: item.title,
                  )));
        } else if (item.subTitle == 'adaptive') {
          Navigator.of(context).push(MaterialPageRoute(
              builder: (ctx) => AdaptivePage(
                    title: item.title,
                  )));
        }
      },
    );
  }
}

class ClickItem {
  final String title;
  final String subTitle;

  ClickItem(this.title, this.subTitle);
}
